<?php

namespace Hilaoyu\LaravelExtend\Services\Realnames;

use Hilaoyu\LaravelExtend\Model;


abstract class RealnamesModelAbstract extends Model
{

    protected $table = 'realnames';
    protected $fillable = [
        'app_id',
        'user_id',
        'name',
        'card_type',
        'card_no',
        'card_img',
        'user_img',
        'status',
        'check_time',
        'remark',
    ];

    protected $casts = [
        'card_img'=>'json',
        'user_img'=>'json',
    ];

    protected $appends =[
      'card_type_name',
      'status_name',
    ];


    static public function AllowedCardType($key=''){
        $key = trim($key);
        $types = [
            "idcard2" => "二代身份证",
        ];

        return $key ? data_get($types,$key,'') : $types;

    }

    public function getValidationRules()
    {

        $rules = [
            'card_type' => 'required|in:'.implode(',',array_keys(static::AllowedCardType())) ,
            'user_id' => 'required|uuid' ,
        ];

        return $rules;
    }
    
    public function getValidationMessages()
    {
        return [
            'card_type.required' => '证件类型不能为空',
            'card_type.in' => '证件类型错误',
            'user_id.required' => '用户错误',
            'user_id.uuid' => '用户错误',
        ];
    }


    public function getCardTypeNameAttribute()
    {
        $type = $this->getAttribute('card_type');
        return static::AllowedCardType($type);
    }

    public function getStatusNameAttribute()
    {
        $status = $this->getAttribute('status');
        if('2' == $status){
            return '审核未通过';
        }elseif ('1' == $status){
            return '审核通过';
        }
        return '待审核';
    }

}
